/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import hibernate.entityes.City;
import org.hibernate.Session;
import hibernate.connection_factory.*;
import org.hibernate.Transaction;
import hibernate.entityes.*;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.EntityManager;
import org.hibernate.Hibernate;
import org.hibernate.Query;

/**
 *
 * @author eleven
 */
public class CityDAOImpl extends ElementDAOImpl<City> implements CityDAO {

    @Override
    public List<City> getCitiesByName(String name) {
        Session session = HibernateUtil.getOrInitSession();
        Query q = session.getNamedQuery("City.findByName");
        q.setParameter("name", name);
        List<City> cities = q.list();
        if (cities != null) {
            for (City city : cities) {
                Hibernate.initialize(city);
            }
        }
        return cities;
    }

    @Override
    public List<City> getAllCities() {
        Session session = HibernateUtil.getOrInitSession();
        Query q = session.getNamedQuery("City.findAll");
        List<City> cities = q.list();
        if (cities != null) {
            for (City city : cities) {
                Hibernate.initialize(city);
            }
        }
        return cities;
    }
}
